package csu.web.jpetstore.web.servlet;

import csu.web.jpetstore.service.VerificationService;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;
import java.io.IOException;

public class VerificationServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        VerificationService vc = new VerificationService();

        BufferedImage image = vc.getImage();
        // 将验证码存入SESSION
        session.setAttribute("code", vc.getText());
        // 输出图象到页面
        ImageIO.write(image, "JPEG", resp.getOutputStream());
    }



}
